<?php
/**
 * @package		Joomla.Administrator
 * @subpackage	com_users
 * @copyright	Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

// Include the component HTML helpers.
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');

// Load the tooltip behavior.
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
$canDo = UsersHelper::getActions();

// custom override user groups
$this->item->groups = array_values((array)$this->item->groups);
$this->item->groups = $this->item->groups[1];
// Get the form fieldsets.
$fieldsets = $this->form->getFieldsets();

$bgAuthorize = new bgAuthorize();
?>

<script type="text/javascript">
	Joomla.submitbutton = function(task){
		if (task == 'user.cancel' || document.formvalidator.isValid(document.id('user-form'))) {
			Joomla.submitform(task, document.getElementById('user-form'));
		}
	}
</script>
<form action="<?php echo JRoute::_('index.php?option=com_users&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="user-form" class="form-validate" enctype="multipart/form-data">
	<div class="width-60 fltlft">
		<fieldset class="adminform bg-none">
			
			<ul class="adminformlist">
                <li><label style="color:red;">※印は入力必須項目です。</label>
                </li>
			<?php foreach($this->form->getFieldset('user_details') as $field):
           
                    if($field->type == 'SQL')
                        echo '<li><label id="jform_groups-lbl" for="jformgroups">権限グループ<span class="star">※</span></label>  
                            '.JHTML::_('Select.genericlist',$this->groups,"jform[groups][]","class='medium'","id","title",$this->item->groups).'</li>';
                    elseif($field->type == 'File'){
                        
                        // giu lai gia tri form chon cc
                        $this->item->USEM_OCBA_CODE = $field->value ? $field->value : $this->item->USEM_OCBA_CODE;

                        echo '<li><label id="jform_USEM_OCBA_CODE-lbl" for="jformUSEM_OCBA_CODE" class=" required">所属<span class="star">※</span></label>
                        <input type="text" name="jform[USEM_OCBA_CODE]" id="jformUSEM_OCBA_CODE" class="inputbox required" size="30" aria-required="true" required="required" aria-invalid="false" value="'.$this->item->USEM_OCBA_CODE.'"/>
                            <a href="#" id="link_ocba_code" style="float:left;line-height:30px;">検索</a>
                            </li>';
                            
                    }else{
                        echo "<li>$field->label $field->input</li>";
                    }
                    
                //echo '<li><label id="jform_USEM_OCBA_CODE-lbl" for="jformUSEM_OCBA_CODE">所属</label>  
                       //     '.JHTML::_('Select.genericlist',$this->centers,"jform[USEM_OCBA_CODE]","class='medium'","OCBA_CODE","OCBA_NAME",$this->item->USEM_OCBA_CODE).'</li>';
                   
                /*
                echo '<li><label id="jform_USEM_OCBA_CODE-lbl" for="jformUSEM_OCBA_CODE">所属</label>
                        <input type="text" name="jform[USEM_OCBA_CODE]" id="jform[USEM_OCBA_CODE]" class="medium" value="'.$this->item->USEM_OCBA_CODE.'"/>
                            <a href="#" id="link_ocba_code" style="float:left;line-height:30px;">検索</a>
                            </li>';
                */
                
                endforeach; ?>
			</ul>
		</fieldset>

	</div>

	<div class="width-40 fltrt hidden">
		<?php
		echo JHtml::_('sliders.start');
		foreach ($fieldsets as $fieldset) :
			if ($fieldset->name == 'user_details') :
				continue;
			endif;
			echo JHtml::_('sliders.panel', JText::_($fieldset->label), $fieldset->name);
		?>
		<fieldset class="panelform">
		<ul class="adminformlist">
		<?php foreach($this->form->getFieldset($fieldset->name) as $field): ?>
			<?php if ($field->hidden): ?>
				<?php echo $field->input; ?>
			<?php else: ?>
				<li><?php echo $field->label; ?>
				<?php echo $field->input; ?></li>
			<?php endif; ?>
		<?php endforeach; ?>
		</ul>
		</fieldset>
		<?php endforeach; ?>
		<?php echo JHtml::_('sliders.end'); ?>

		<input type="hidden" name="task" value="" />
		<?php echo JHtml::_('form.token'); ?>
	</div>
</form>
<script>
jq('.adminformlist input.hidden, .adminformlist fieldset.hidden').parent().css('display','none');
if(!<?php echo $this->item->id ?>){
    jq('#jform_sendEmail').val('1');
}
/*show a dialog box: center search */
    jq('#link_ocba_code').bind('click', function(e){
        e.preventDefault();
            zb = new jq.Zebra_Dialog('', {
                source:  {'ajax': 'index.php?option=com_users&view=user&task=popup_ocba&layout=popup_ocba&tmpl=component'},
                height: 800,
                width: 550,
                title:  'センター・クラブ検索',
                type:  '',
                buttons:  [
                    {caption: '閉じる', callback: function() { }},
                        
                ]
            });
    });
    /*select center id */
    jq(".link_ocba_code").live("click",function(){
        //var id = jq(this).html();
        var id = jq("#ocba_code_temp").val();
        jq("#jformUSEM_OCBA_CODE").val(id);
        zb.close();
    });
</script>

<script>
    jq(document).ready(function() {
       var username = jq("#jform_username").val();
       var ocbacode = jq("#jformUSEM_OCBA_CODE").val();
       var name = jq("#jform_name").val();
       //var email = jq("#jform_email").val();
       
       if(username != ''){
       <?php if($this->checkEO){ ?>
            jq("#jform_username").attr('readonly',true);
            jq("#jform_username").attr('class','readonly inputbox medium');
            
            jq("#jformUSEM_OCBA_CODE").attr('readonly',true);
            jq("#jformUSEM_OCBA_CODE").attr('class','readonly inputbox medium');
            jq("#link_ocba_code").hide();
            
            jq("#jform_name").attr('readonly',true);
            jq("#jform_name").attr('class','readonly inputbox medium');
            var groups_name = '';
            jq( "#jformgroups option:selected" ).each(function() {
                groups_name = jq( this ).text();
            });
            
            jq("#jformgroups").attr('disabled', true);
            jq("#jformgroups").attr('style','font-family: Arial, Helvetica, sans-serif;font-size: 1.091em;padding-top: 1px;border: 0;font-weight: bold;color: #666;background-color: #F1F1F1;');
            
            //jq("#jform_email").attr('readonly',true);
            //jq("#jform_email").attr('class','readonly inputbox medium');
            
            
            jq("#jform_username").wrap( "<span style='float:left;margin:5px; width: 150px;' id='span_username'></span>" );
            jq("#jformUSEM_OCBA_CODE").wrap( "<span style='float:left;margin:5px; width: 150px;' id='span_ocbacode'></span>" );
            jq("#jform_name").wrap( "<span style='float:left;margin:5px; width: 150px;' id='span_name'></span>" );
            jq("#jformgroups").wrap( "<span style='float:left;margin:5px; width: 150px;' id='span_groups'></span>" );
            //jq("#jform_email").wrap( "<span style='float:left;margin:5px; width: 150px;' id='span_email'></span>" );
            
            /* label */
            jq("#span_username").html('<label id = "jform_username">'+username+'</label>');
            jq("#span_ocbacode").html('<label id = "span_ocbacode">'+ocbacode+'</label>');
            jq("#span_name").html('<label id = "span_name">'+name+'</label>');
            jq("#span_groups").html('<label id = "span_groups">'+groups_name+'</label>');
            //jq("#span_email").html('<label id = "span_email">'+email+'</label>');
       <?php } ?>
            
       } 
       /**** 11/11/2013 */
       jq('#jform_lastvisitDate-lbl').parent().css('display','none');
       jq('#jform_registerDate-lbl').parent().css('display','none');
       jq('#jform_lastResetTime-lbl').parent().css('display','none');
       jq('.star').html('※');


        <?php if($bgAuthorize->getUserGroup() != 8 ):?>
       if(jq('#jform_username').val() ){
            jq('#jform_username, #jformUSEM_OCBA_CODE, #jform_name')
                    .attr('readonly', 'readonly').addClass('readonly');

            jq('#link_ocba_code').hide();

            var txt = jq('#jformgroups').find('option[selected]').html();
            jq('#jformgroups').hide().after('<input type="text" value="'+txt+'" class="readonly"/>');
        }
        <?php endif ?>
       
    });
</script>